package com.my.interview.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class MySocketClient {

    public static void main(String[] args) {

        String msg = "my data is hahahahah \n from socketClient";
        try{
            Socket socket = new Socket("127.0.0.1",8089);
            PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            printWriter.print(msg);
            printWriter.flush();
            String line = bufferedReader.readLine();
            System.out.println("get data from serverSocket is :" + line);

            printWriter.close();
            bufferedReader.close();
            socket.close();

        }catch (UnknownHostException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }


    }
}
